"""
@Time : 2021/7/4 11:46 AM 
@Author : Xiaoming
简单flask程序，读写mongo
"""

import json
from flask import Flask
from flask import request

from db.mongoClient import MongoClient
app = Flask(__name__)

mongo = MongoClient()


@app.route('/get')
def get():
    user = mongo.get_one()
    if user is None:
        return 'no user'
    return user['user']


@app.route('/put', methods=['POST'])
def put():
    user = json.loads(request.get_data().decode('utf-8'))
    mongo.insert_one(user)
    return 'success'


if __name__ == '__main__':
    # 设置调试模式，生产模式的时候要关掉debug
    app.debug = True
    app.run('0.0.0.0')
